<!DOCTYPE html>
<html xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>vue-boot 部门员工</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../static/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../static/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../static/css/style.css">
    <link rel="stylesheet" href="../static/plugins/pageination/zpageNav.css">
    <script src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../static/plugins/bootstrap/js/bootstrap.min.js"></script>
    <style>
        .fileinput-button { position: relative; display: inline-block; overflow: hidden; } .fileinput-button input{ position: absolute; left: 0px; top: 0px; opacity: 0; -ms-filter: 'alpha(opacity=0)'; }
    </style>
</head>

<body class="hold-transition skin-red sidebar-mini">

<div id="app">
    <div class="box-header with-border" style="height: 64.5px;line-height: 54px;">
        <h3 class="box-title">部门员工</h3>
    </div>
    <div class="box-body">
        <!-- 数据表格 -->
        <div class="table-box">
            <!--工具栏-->
            <div class="pull-left">
                <div class="form-group form-inline">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" title="新建" @click="clear()" data-toggle="modal"
                                data-target="#editModal" sec:authorize="hasRole('dptadmin')"><i class="fa fa-file-o"></i> 新建
                        </button>
                        <button sec:authorize="hasRole('dptadmin')" type="button" class="btn btn-default" title="删除" @click="deleteDepartments()"><i
                                class="fa fa-trash-o"  ></i> 删除
                        </button>
                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i
                                class="fa fa-refresh"></i> 刷新
                        </button>
                        <button type="button" class="btn btn-success fileinput-button"  title="导出" @click="outPutExcel()" ><i
                                class="fa fa-refresh" ></i> 导出Excel
                        </button>
                        <span class="btn btn-success fileinput-button">
                            <span >导入Excel</span>
                            <input type="file" >
                         </span>


                    </div>
                    <div class="box-tools pull-right">
                        <div class="has-feedback" style="margin-left: 750px; font-size: 16px">
                            员工姓名查询: <input type="text" v-model="key" class="form-control">
                            <input class="btn btn-default" type="button" @click="pageHandler(1)" value="查询">
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-tools pull-right">
                <div class="has-feedback"></div>
            </div>
            <!--数据列表-->
            <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                <thead>
                <tr>
                    <th class="" style="padding-right:0px">
                        <input id="selall" type="checkbox" class="icheckbox_square-blue">
                    </th>
                    <th class="sorting_asc">员工编号</th>
                    <th class="sorting_asc">员工姓名</th>
                    <th class="sorting_asc">员工部门</th>
                    <th class="sorting_asc">员工电话</th>
                    <th class="sorting_asc" >员工地址</th>
                    <th class="sorting_asc" sec:authorize="hasRole('dptadmin')">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="departmentUserItem in departmentUserList">
                    <td><input type="checkbox" @click="deleteSelect($event,departmentUserItem.id)"></td>
                    <td>{{departmentUserItem.id}}</td>
                    <td>{{departmentUserItem.username}}</td>
                    <td>{{departmentUserItem.dptName}}</td>
                    <td>{{departmentUserItem.phone}}</td>
                    <td>{{departmentUserItem.address}}</td>
                    <td class="text-center">
                        <button sec:authorize="hasRole('dptadmin')" type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal"
                                @click="findById(departmentUserItem.id)">修改
                        </button>
                        <!--                        <button type="button"  @click="changeStatus(departmentItem.id)" style="outline:none;border-radius:4px;font-size:2px;width:36px;height:22px;background-color: red;color: white;border: none">-->
                        <!--                        </button>-->
                    </td>
                </tr>

                </tbody>

            </table>

        </div>
    </div>
    <!--分页-->
    <zpagenav v-bind:page="page" v-bind:page-size="pageSize" v-bind:total="total"
              v-bind:max-page="maxPage" v-on:pagehandler="pageHandler">
    </zpagenav>
    <!-- 编辑窗口 -->
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">用户编辑</h3>
                </div>
                <div class="modal-body">
                    <table class="table table-bordered table-striped" width="800px">
                        <tr>
                            <td>员工姓名</td>
                            <td><input class="form-control" v-model="dptInfo.username"></td>
                        </tr>
                        <tr>
                            <td>员工部门</td>
                            <td>
                            <select class="form-control" v-model="dptInfo.dptName">
<!--                                <option value="-1">请选择部门</option>-->
                                <option v-for="departmentItem in departmentList" selected="{{dptInfo.dptName}}">{{departmentItem.dptName}}</option>
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td>员工电话</td>
                            <td><input class="form-control" v-model="dptInfo.phone" ></td>
                        </tr>
                        <tr>
                            <td>员工地址</td>
                            <td><input class="form-control" v-model="dptInfo.address"></td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" @click="save()">保存</button>
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>

</body>


<script src="../static/plugins/vue/vuejs-2.5.16.js"></script>
<script src="../static/plugins/vue/axios-0.18.0.js"></script>
<script src="../static/plugins/vue/qs.js"></script>
<script src="../static/plugins/pageination/zpageNav.js"></script>
<script>

    new Vue({
        el: "#app",
        data: {
            page: 1,//当前页
            pageSize: 5,//每页显示数据
            total: 0,//记录总数
            key: '', //查询关键字
            departmentUserList: [],
            departmentList: [],
            selectIds:[],
            dptInfo: {},
            selectId: -1,//编辑回显的id
        },
        methods: {
            pageHandler: function (page) {
                var _this=this;
                this.page = page;
                axios.post("/departmentUser/search?page="+page+"&size="+this.pageSize+"&key="+this.key).then(function (response) {
                    _this.departmentUserList=response.data.data.records;
                    _this.total=response.data.data.total;
                    _this.pageSize = response.data.data.size;
                }).catch(function (result) {
                    window.alert(result);
                });
            },
            deleteSelect: function (event, id) {
                if (event.target.checked) {
                    this.selectIds.push(id);
                } else {
                    var idx = this.selectIds.indexOf(id);
                    this.selectIds.splice(idx, 1);
                }
            },
            deleteDepartments: function () {
                var _this = this;                     //将对象行序列化成url进行传输
                axios.post("/departmentUser/delDepartmentUsers",Qs.stringify({ids:_this.selectIds},{indices:false})).then(function (response) {
                    if (response.data.code == 200) {
                        _this.pageHandler(_this.page);
                        _this.selectIds = {};
                        window.alert(response.data.msg);
                    } else {
                        window.alert(response.data.msg);
                    }
                }).catch(function (result) {
                    window.alert(result);
                });
            },
            findAlldpt: function () {
                var _this = this;                     //将对象行序列化成url进行传输
                axios.post("/department/findAlldpt").then(function (response) {
                    _this.departmentList = response.data.data.list;
                }).catch(function (result) {
                    window.alert(result);
                });
            },
            findById: function (id) {
                var _this = this;                     //将对象行序列化成url进行传输
                axios.post("/departmentUser/findById?id="+id).then(function (response) {
                    _this.dptInfo = response.data.data.user;
                    _this.selectId = _this.dptInfo.id;
                }).catch(function (result) {
                    window.alert(result);
                });

            },
            clear: function () {
                this.dptInfo = {};
            },
            save: function () {
                var _this = this;
                var url = "";
                if (_this.dptInfo.id != null) { //编辑
                    url = "/departmentUser/edit";
                } else {
                    url = "/departmentUser/add";
                }
                _this.dptInfo.id = this.selectId;
                axios.post(url,_this.dptInfo).then(function (response) {
                    if (response.data.code==200) {
                        _this.pageHandler(_this.page);
                        window.alert(response.data.msg);
                    } else {
                        window.alert(response.data.msg);
                    }
                }).catch(function (result) {
                    window.alert(result);
                });
            },
            outPutExcel: function () {
                window.location.href = "/outPutDepartmentUserExcel";
                window.alert("导出Excel成功！");

            }
        },
        created: function () {
            this.pageHandler(1);
            this.findAlldpt();
        }
    })

</script>


</html>